package interview.stringmatching;

public class StringMatching {
	public boolean match(String source, String pattern) {
		String[] strs = pattern.split("\\*");
		int prev = -1;
		for(int i = 0; i < strs.length; i++) {
			if(!strs[i].equals("")) {
				int idx = source.indexOf(strs[i], 0);
				while(idx > -1 && idx < prev) {
					prev = source.indexOf(strs[i], idx + strs[i].length() - 1);
				}
				if(idx == -1) {
					return false;
				}
				prev = idx;
			}
		}
		
		return true;
	}
}
